package com.scqzy.shengchunqiang.sword2offer.day21;

/**
 * @Description: 剑指 Offer 15. 二进制中1的个数
 * @Author 盛春强
 * @Date 2021/8/28 22:34
 */
public class HammingWeight {
    public int hammingWeight(int n) {
        int c = 0;
        for (int i = 0; i < 32; i++) {
            if ((n & (1 << i)) != 0) {
                c++;
            }
        }
        return c;
    }
}
